package ch.abcm.remsmobile.REMSMobile;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import ch.abcm.remsmobile.REMSMobile.multicastreceiver.REMSMulticastReceiver;
import ch.bfh.abch.rems.REMSMulticastController;

public class StartupJob extends BroadcastReceiver{
    
	private static boolean isAlreadyRunning = false;
    private static final String TAG = "StartupJob";
	public static final String START_UP = "ch.bfh.abcm.rems.NetworkController.START_UP";


    @Override
    public void onReceive(Context context, Intent intent) {
        Log.d(TAG, "Received Intent: "+ intent.getAction());
        startMulticastReceiver(context);
    }

	private void startMulticastReceiver(Context context) {
		Log.d(TAG, "Start MulticastReceiver (running: "+isAlreadyRunning+")");
		
		if (!isAlreadyRunning) {
			new REMSMulticastController().startMulticastReceiver(new REMSMulticastReceiver(context));
			isAlreadyRunning = true;
		}else {
			Log.d(TAG, "Receiver is already Running");
		}
		
	}

}
